package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile     string `gorm:"type:varchar(11);not null"`
	Password   string `gorm:"type:varchar(32);not null"`
	QQ         string `gorm:"type:varchar(32);not null"`
	WeChatCode string `gorm:"type:varchar(32);not null"`
	HeadImage  string `gorm:"type:varchar(500);not null"`
	NickName   string `gorm:"type:varchar(50);not null"`
	NovelCode  string `gorm:"type:varchar(50);not null"`
	Sex        string `gorm:"type:varchar(50);not null"`
	Desc       string `gorm:"type:varchar(50);not null"`
}

func (u *User) UserFirstOrCreate(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile = ?", mobile).FirstOrCreate(u).Error
}

func (u *User) FindUser(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile = ?", mobile).First(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).First(u).Error
}

func (u *User) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile = ?", mobile).First(u).Error
}

func (u *User) UpdatePassword(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
